package health.lm.com.shop.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.jakewharton.rxbinding2.view.RxView;
import com.lm.sjy.titlebar.widget.CommonTitleBar;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.data.HttpCST;
import health.lm.com.router.ARouterConstant;
import health.lm.com.shop.R;
import health.lm.com.shop.R2;

/**
 * Created by Android Studio .
 * 作者：zhong
 * 日期：2018/11/22
 * 邮箱：15206394364@163.com
 * 介绍：支付结果页面，展示效果
 * 接收两个参数 pay_status pay_description
 * pay_status   支付结果状态 成功、失败
 * pay_description 支付后的说明信息
 * 修订：====================
 */
@Route(path = ARouterConstant.MallPaymentResultActivity)
public class PaymentResultActivity extends XActivity {
    public static final int PAY_STATUS_SUCCESS = 1;
    public static final int PAY_STATUS_FAIL = 0;

    @BindView(R2.id.title_bar)
    CommonTitleBar mTitleBar;
    @BindView(R2.id.iv_payment)
    ImageView mIvPayment;
    @BindView(R2.id.tv_payment_status)
    TextView mTvPaymentStatus;
    @BindView(R2.id.tv_payment_description)
    TextView mTvPaymentDescription;
    @BindView(R2.id.btn_back)
    Button mBtnBack;
    @BindView(R2.id.btn_continue)
    Button mBtnContinue;

    private String PaySuccess = "支付成功";
    private String PayFail = "支付失败";

    protected void initWidget() {
        mTitleBar.setListener((v, action, extra) -> finish());
    }

    @SuppressLint("CheckResult")
    protected void processLogic() {
        int payment_result = getIntent().getIntExtra(HttpCST.PAY_STATUS, 0);
        String description = getIntent().getStringExtra(HttpCST.PAY_DESCRIPTION);
        mTitleBar.getCenterTextView().setText(payment_result == PAY_STATUS_SUCCESS ? PaySuccess : PayFail);
        if (payment_result == PAY_STATUS_SUCCESS)
            mIvPayment.setImageResource(R.mipmap.pay_icon_successful);
        else mIvPayment.setImageResource(R.mipmap.pay_icon_fail);
        mTvPaymentStatus.setText(payment_result == PAY_STATUS_SUCCESS ? PaySuccess : PayFail);
        mTvPaymentDescription.setText(description == null ? "" : description);

        mBtnBack.setText("返回订单");
        mBtnContinue.setText("返回");
        //String order_Id = getIntent().getStringExtra(HttpCST.ORDER_ID);
        RxView.clicks(mBtnBack).throttleFirst(3, TimeUnit.SECONDS).subscribe(o -> {
            ARouter.getInstance().build(ARouterConstant.OrderListActivity).navigation();
        });
        RxView.clicks(mBtnContinue).throttleFirst(3, TimeUnit.SECONDS).subscribe(o -> finish());
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        initWidget();
        processLogic();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_mall_payment_result;
    }

    @Override
    public Object newP() {
        return null;
    }
}
